#pragma once
#include<iostream>
#include<string>

std::string OP = "+-*/%";

enum{
    DivZero = 1,
    ModZero = 2,
    Unknow = 3
};

class Task
{
public:
    Task(){}
    Task(int x, int y, char op)
    :_data1(x),_data2(y),_op(op),_res(0),_exitcode(0)
    {}
    void run()
    {
        switch (_op)
        {
        case '+':
        {
            _res = _data1 + _data2;
            break;
        }
        case '-':
        {
            _res = _data1 - _data2;
            break;
        }
        case '*':
        {
            _res = _data1 * _data2;
            break;
        }
        case '/':
        {
            if(_data2 == 0) _exitcode = DivZero;
            else _res = _data1 / _data2;
            break;
        }
        case '%': 
        {
            if(_data2 == 0) _exitcode = ModZero;
            else _res = _data1 % _data2;
            break;
        }               
        default:
            _exitcode = Unknow;
            break;
        }
    }
    ~Task()
    {

    }
    std::string GetTask()
    {
        std::string r = std::to_string(_data1);
        r += _op;
        r += std::to_string(_data2);
        r += "=?";
        return r;
    }

    std::string GetRes()
    {
        std::string r = std::to_string(_data1);
        r += _op;
        r += std::to_string(_data2);
        r += "=";
        r += std::to_string(_res);
        r += "[code: ";
        r += std::to_string(_exitcode);
        r += "]";

        return r;
    }
    void operator()()//仿函数
    {
        run();
    }
private:
    int _data1;
    int _data2;
    char _op;
    int _res; // 运算结果
    int _exitcode; //退出码
};